IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'ChaptersGet')
	BEGIN
		DROP  Procedure  ChaptersGet
	END

GO

CREATE Procedure ChaptersGet
@SagaID int,
@CreatorID int = Null
AS
If(@CreatorID Is Null )
Begin
	Select 
	 ChapterID,
	SagaID,
	Title,
	Header,
	Footer,
	StartMonth,
	StartYear,
	EndMonth,
	EndYear,
	ViewOrder,
	CreatorID,
    AccessType,
	IsPrivate,
	LastUpdated,
	CreatedDate
	From Chapter
	Where SagaID = @SagaID
END
Else
Begin
	Select 
	 ChapterID,
	SagaID,
	Title,
	Header,
	Footer,
	StartMonth,
	StartYear,
	EndMonth,
	EndYear,
	ViewOrder,
	CreatorID,
    AccessType,
	IsPrivate,
	LastUpdated,
	CreatedDate
	From Chapter
	Where SagaID = @SagaID And IsPrivate= 0 OR CreatorID = CreatorID 
END

GO

